package com.example.inventoryservice.WarehouseQueryDemo;

import java.util.Arrays;
import java.util.List;

// 演示如何使用策略模式查询仓库
public class WarehouseQueryDemo {
    public static void main(String[] args) {
        // 模拟一些仓库数据
        List<Warehouse> allWarehouses = Arrays.asList(
                new Warehouse(1L, "北京仓库", "ORG001", "ENTITY001", false),
                new Warehouse(2L, "上海仓库", "ORG002", "ENTITY001", false),
                new Warehouse(3L, "广州仓库", "ORG003", "ENTITY002", true),
                new Warehouse(4L, "深圳仓库", "ORG004", "ENTITY001", true)
        );

        // 创建查询上下文
        WarehouseQueryContext context = new WarehouseQueryContext();

        // 1. 测试有库存组织的情况
        String inventoryOrg = "ORG001";
        String accountingEntity = "ENTITY001";
        context.setStrategy(inventoryOrg);

        List<Warehouse> result1 = context.executeFilter(allWarehouses, inventoryOrg, accountingEntity);
        System.out.println("按库存组织" + inventoryOrg + "过滤的结果:");
        result1.forEach(warehouse -> System.out.println("- " + warehouse.getName()));

        // 2. 测试无库存组织的情况
        inventoryOrg = ""; // 空值表示不按库存组织过滤
        context.setStrategy(inventoryOrg);
        List<Warehouse> result2 = context.executeFilter(allWarehouses, inventoryOrg, accountingEntity);
        System.out.println("\n按会计主体" + accountingEntity + "过滤的结果:");

        result2.forEach(warehouse -> System.out.println("- " + warehouse.getName()));
    }
}
